home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / printing / techpp.arc / PSCONV.C < prev    next >
Text File  |  1985-11-20  |  2KB  |  70 lines

  1. /* XmodToPs -Translate (Fortran) xmodem file into c text file; wrap lines
  2.    that exceed 100 chars
  3.    This version includes a file HEADER.PS (if it exists) following the first
  4.    ^D */
  5. #include stdio
  6. #include ctype
  7.  
  8. main()
  9. {
  10.     int ch, eofs, len, wrap;
  11.     char header[128], fname[128];
  12.     FILE *in, *out, *hdr;
  13.  
  14.     printf( "Input file? " );
  15.     gets( fname );
  16.     if( (in = fopen( fname, "r" )) == NULL )
  17.     {
  18.         printf( "Unable to open input file: %s\n", fname );
  19.         exit();
  20.     }
  21.     printf( "Output file? " );
  22.     gets( fname );
  23.     if( (out = fopen( fname, "w" )) == NULL )
  24.     {
  25.         printf( "Unable to open output file: %s\n", fname );
  26.         exit();
  27.     }
  28.     eofs = len = wrap = 0;
  29.     while( (ch = fgetc( in )) != EOF )
  30.         if( ch == '\r' || ch == '\n' )
  31.         {
  32.             fputc( '\n', out );
  33.             len = wrap = 0;
  34.         }
  35.         else if( ch == '\0' ) continue;
  36.         else if( (ch == '\004') && (++eofs < 2) )
  37.         {    /* ^D = PS EOF */
  38.             fprintf( out, "\004\n" );
  39.             len = wrap = 0;
  40.             if( (hdr = fopen( "header.ps", "r" )) != NULL )
  41.             {
  42.                 while( fgets( header, 128, hdr ) != NULL )
  43.                     fputs( header, out );
  44.                 fclose( hdr );
  45.             }
  46.         }
  47.         else if( isspace( ch ) )
  48.         {
  49.             if( ++len > 80 ) wrap = TRUE;
  50.             if( wrap )
  51.             {
  52.                 fputc( '\n', out );
  53.                 len = wrap = 0;
  54.             }
  55.             else fputc( ch, out );
  56.         }
  57.         else
  58.         {
  59.             fputc( ch, out );
  60.             if( len == 127 )
  61.             {
  62.                 fputc( '\n', out );
  63.                 len = wrap = 0;
  64.             }
  65.             else if( ++len > 80 ) wrap = TRUE;
  66.         }
  67.     fclose( in );
  68.     fclose( out );
  69. }    /* main */
  70. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə